#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;
const int inf = 0x3f3f3f3f;

namespace F {
	const int N = 210;
	const int M = 1e5 + 10;
	struct edge {
		int v, w, nxt;
	} e[M];
	int h[N], cnt = 1, S, T, d[N], now[N];
	ll maxflow, ret;
	void tlink(int u, int v, int w) { e[++cnt] = (edge) { v, w, h[u] }; h[u] = cnt; }
	void link(int u, int v, int w) { tlink(u, v, w), tlink(v, u, 0); }
	void setst(int s, int t) { S = s, T = t; }
	bool bfs() {
		memset(d, 0, sizeof d); d[S] = 1; queue < int > q; q.ep(S); now[S] = h[S];
		while(q.size()) {
			int x = q.front(); q.pop();
			for(int i = h[x], y; i; i = e[i].nxt)
				if(e[i].w && !d[y = e[i].v]) {
					now[y] = h[y]; d[y] = d[x] + 1; q.ep(y);
					if(y == T) return true;
				}
		} return false;
	}
	int dinic(int x, int flow) {
		if(x == T) return flow;
		int ret = flow;
		for(int i = now[x], y; i && ret; i = e[i].nxt) {
			now[x] = i;
			if(e[i].w && d[y = e[i].v] == d[x] + 1) {
				int t = dinic(y, min(e[i].w, ret));
				if(!t) d[y] = 0;
				ret -= t; e[i].w -= t; e[i ^ 1].w += t;
			}
		} return flow - ret;
	}
	ll runit() {
		maxflow = ret = 0;
		while(bfs()) while(ret = dinic(S, inf)) maxflow += ret;
		return maxflow;
	}
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	int n = in, m = in, s = in, t = in;
	F :: setst(s, t);
	rep(i, 1, m) {
		int u = in, v = in, w = in;
		F :: link(u, v, w);
	} cout << F :: runit() << endl;
	return 0;
}
